{% if pageData["fullpage"] %}
{#% extends '/ic/dashboard.html' %#}
{% endif %}
{% block content %}
{% if pageData["waiting"] %}
    <div class="alert alert-warning alert-dismissible" role="alert">
      <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
      <strong>Attenzione!</strong><br />La tua procedura di registrazione è in attesa di attivazione.
    </div>
             <a href="/italiaCives/dashboard" class="btn btn-block collapsed"><i class="fa fa-home fa-3x"></i></a>
{% else %}
<br/>
{% if leggiInSessione(sezione="Main", chiave="username") %}
<div class="jumbotron alert alert-danger">
    <h3>Attenzione!</h3>
    <h5>Risulti già un utente ItaliaCives, Se vuoi inviare una segnalazione anche in questo comune, richiedi l'autorizzazione.</h5>

</div>
            <div class="panel panel-warning">
                <div class="panel-heading">
                      <p  class="panel-title">
                    <a style="white-space: normal;" data-slidepanel="panel" href="/italiaCives/insertinthisente" class="btn btn-lg btn-block">Richiedi l'autorizzazione</a>
                </p></div>

            </div>



{% else %}
<div class="jumbotron alert alert-danger">
    <h3>Attenzione!</h3>
    <h5>Per poter visualizzare o effettuare una segnalazione è necessario <b>registrarsi</b> o effettuare il <b>login</b> su ItaliaCives</h5>
    <h6>Compila i campi sottostanti</h6>
</div>
<hr>
<div class="row">
    <div class="col-md-12">
        <div class="panel-group" id="accordion">
            <div class="panel">
                <div class="panel-heading">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="btn giallino btn-lg btn-block collapsed">LOGIN</a>
                </div>
                    <div id="collapseOne" class="panel-collapse collapse" style="height: 0px;">
                        <div class="panel-body">
                            <div class="row omb_row-sm-offset-3"></div>
                                <div class="col-xs-12 col-sm-6">
                                    <form class="omb_loginForm" action="/italiaCives/login_ic" autocomplete="off" method="POST">
                                        <div class="input-group">
                                            <span class="input-group-addon"><i class="fa fa-user"></i></span>
                                                <input type="email" class="form-control" name="username" placeholder="email address" required>
                                        </div>
                                            <span class="help-block"></span>
                                        <div class="input-group">
                                            <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                                                <input  type="password" class="form-control" name="password" placeholder="Password" required>
                                        </div>
                            <br/>
                                        <button class="btn btn-lg btn-danger btn-block" type="submit">Login</button>
                                    </form>
                                </div>
                        </div>
                    </div>

            </div>
        </div>

            <div class="panel">
                <div class="panel-heading">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" class="btn giallino btn-lg  btn-block collapsed">REGISTRATI</a>
                </div>
                <div id="collapseTwo" class="panel-collapse collapse" style="height: 0px;">
                    <div class="panel-body">
                        <div class="well">
                            <form class="form-horizontal" id="ae_form" action="/italiaCives/registrazione" method="post" role="form">
                                <fieldset>
                                    <input type="hidden" name="id" value="{{pageData['dao'].id}}"/>
                                    <div class="form-group" title="">
                                        <label class="col-sm-2 col-lg-2 control-label" for="email">Email:</label>
                                        <div class="col-sm-5 col-lg-5">
                                            <input required class="validate[required,custom[email],{{'ajax[ajaxEmailOpeCall]' if not pageData['dao'].id}}] text-input"  value='{{pageData["dao"].email|nonone}}' type="email" name="email" id="email"  />
                                        </div>
                                    </div>

                                    <div class="form-group" title="">
                                       <label class="col-sm-2 col-lg-2 control-label" for="password">Password:</label>
                                       <div class="col-sm-5 col-lg-5">
                                            <input class="validate[minSize[5],{{'required' if not pageData['dao'].id}} ] text-input medium"  type="password" name="password" id="password"  />
                                        </div>
                                    </div>

                                    <div class="form-group" title="">
                                       <label class="col-sm-2 col-lg-2 control-label" for="re-password">Re Password:</label>
                                       <div class="col-sm-5 col-lg-5">
                                            <input class="validate[{{'required' if not pageData['dao'].id}}, equals[password],minSize[5]] text-input medium"  type="password" name="re-password" id="re-password"  />
                                        </div>
                                    </div>

                                    <div class="form-group" title="">
                                        <label class="col-sm-2 col-lg-2 control-label" for="cognome">Cognome:</label>
                                        <div class="col-sm-5 col-lg-5">
                                            <input class="form-control" type="text" id="cognome" name="cognome" value='{{pageData["dao"].cognome|nonone}}' />
                                        </div>
                                    </div>
                                    <div class="form-group" title="">
                                        <label class="col-sm-2 col-lg-2 control-label" for="nome">Nome:</label>
                                        <div class="col-sm-5 col-lg-5">
                                            <input class="form-control" type="text" id="nome" name="nome" value='{{pageData["dao"].nome|nonone}}' />
                                        </div>
                                    </div>

                                    <div class="form-group" title="">
                                        <label class="col-sm-2 col-lg-2 control-label" for="cellulare">Cellulare:</label>
                                        <div class="col-sm-5 col-lg-5">
                                            <input class="form-control" type="text" id="cellulare" name="cellulare" value='{{pageData["dao"].cellulare|nonone}}' />
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-sm-offset-3">
                                            <label class="checkbox-inline">
                                            <input type="checkbox" id="privacy" name="privacy"  {{ "checked" if pageData["dao"].privacy == True }} >
                                            Privacy</label>
                                        </div>
                                    </div>
                                </fieldset>
                                <div class="form-group" title="Bottoni di salvataggio e reset del form">
                                    <div class="col-sm-12 col-lg-8 col-sm-offset-2">
                                        <input class="btn-lg btn-danger" type="submit" value="Registrati" name="add"/>
                                    </div>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
    </div>
</div>
{% endif %}
{% endif %}
{#% if pageData["fullpage"] %#}
{% endblock %}
{#% endif %#}
<script src="/tpl/pg/js/plugins/jQuery-Validation-Engine/js/languages/jquery.validationEngine-en.js"></script>
<script src="/tpl/pg/js/plugins/jQuery-Validation-Engine/js/jquery.validationEngine.js"></script>
<script>
$(document).ready(function(){

$(".omb_loginForm").submit(function(e) {
    var url = "/italiaCives/login_ic"; // the script where you handle the form input.
    $.ajax({
           type: "POST",
           url: url,
           data: $(".omb_loginForm").serialize(), // serializes the form's elements.
           success: function(data)
                       {
                        var msg = $.parseJSON(data);
                        if (msg["result"] == "OK") {
                            alert(msg["msg"]);
                            setTimeout("window.location.href='/italiaCives/dashboard';",500);
                        } else {
                            err = msg["msg"]
                            alert(err)
                        }
                          //alert(data); // show response from the php script.
                       }
         });

    return false; // avoid to execute the actual submit of the form.
});


$( "#ae_form" ).validationEngine({
                    prettySelect : true,
                    useSuffix: "_chosen",
                });

});
</script>
